var apiMWAP_fg = {};
apiMWAP_fg.pagechange_callback = undefined;
apiMWAP_fg.pagechange_target = undefined;


apiMWAP_fg.pagechange_apiresp = function(result){
	if( result.status == "Done"){
		apiMWAP_fg.log('resp_pagechange='+ result.status);
	} else if(apiMWAP_fg.pagechange_callback){
		apiMWAP_fg.pagechange_callback( apiMWAP_fg.pagechange_target);
	}
	apiMWAP_fg.pagechange_callback = undefined;
	apiMWAP_fg.pagechange_target = undefined;
};

apiMWAP_fg.pagechange = function(target, callback){
	var request = {};
	apiMWAP_fg.pagechange_callback = callback;
	apiMWAP_fg.pagechange_target = target;
  request.action = 'apipagechange';
  request.target = target;
	chrome.extension.sendRequest( request, function(response){ apiMWAP_fg.pagechange_apiresp(response);});
};

apiMWAP_fg.resp_init = function(result){
	apiMWAP_fg.log('resp_init='+ result[0]);
};

apiMWAP_fg.init = function(){
	var request = {};
  request.action = 'initapi';
	request.scriptid = 'sp_adin';
	request.scriptsrc = 'http://mafia.stealthpartner.com/mafia/addin.mwap.js?open&rnd'+Math.random();
	chrome.extension.sendRequest(request, function(response) { apiMWAP_fg.resp_init(response);});
};
apiMWAP_fg.registerHandler = function( obj){
	
	
};